<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="用户名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder=""
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="app类型">
        <el-select v-model="queryParams.informationType" placeholder="请选择app类型" clearable size="small" prop="informationType">
          <el-option
            v-for="dict in msgOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="opinionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="app类型" align="center" prop="informationType":formatter="informationTypeFormat"  />
      <el-table-column label="反馈内容" align="center" prop="despriction"  min-width="50" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:opinion:edit']"
          >查看详情</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改意见反馈对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="反馈内容" prop="informationType">
        <div>{{form.despriction}}</div>
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">确定</el-button>
    </div>
  </el-dialog>
  </div>
</template>

<script>
import { listOpinion, queryOrinion, getOpinion, delOpinion, addOpinion, updateOpinion, exportOpinion } from "@/api/system/opinion";
import { getToken } from '@/utils/auth'
import { upload } from "@/api/system/type";
export default {
  name: "Opinion",
  data() {
    return {
      // 遮罩层
      data:{
        opinionId:"",
        informationType:"",
      },
      loading: true,
      // 选中数组
      ids: [],
      msgOptions:[],
      fileList:[],
      headers:{
        'Authorization': null
      },
      // //url  上传接口地址
      url:null,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 意见反馈表格数据
      opinionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        despriction: undefined,
        informationType: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_msg ").then(response => {
      this.msgOptions = response.data;
    });
  },
  methods: {
    informationTypeFormat(row, column){
      return this.selectDictLabel(this.msgOptions, row.informationType);
    },
    /** 查询意见反馈列表 */
    getList() {
      this.loading = true;
      listOpinion(this.queryParams).then(response => {
        this.opinionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        opinionId: undefined,
        userId: undefined,
        despriction: undefined,
        informationType: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.opinionId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */

    /** 查看按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.data.opinionId=  row.opinionId;
      this.data.informationType =row.informationType;
      queryOrinion(this.data).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看详情";
      });
    },
    /** 提交按钮 */

  }
};
</script>
